#include "fileinfo.h"

#include <stdlib.h>
#include <string.h>




namespace
{
char char_to_lower (char ch)
{
	if (ch >= 'A' && ch <= 'Z')
		{
			return 'a' + (ch - 'A');
		}
	return ch;
}
}
ceFileInfo::ceFileInfo(const char *filename)
{

	_location = "";
	_name = "";
	_extension = "";
	char* tmpname = strdup(filename);

	char* locptr = tmpname;
	char* extptr = 0;
	char* nameptr = 0;
	int length = strlen(tmpname);
	for (int i=length-1; i>=0; --i)
		{

			char c = tmpname[i];
			if (c == '.')
				{
					if (!extptr)
						{
							tmpname[i] = 0;
							extptr = tmpname + i + 1;
						}
					}
			else if (c == '/' || c == '\\')
				{
					tmpname [i] = 0;
					nameptr = tmpname + i + 1;
					break;
				}
		}

	for (int i=0; i<length; ++i)
		{
			tmpname [i] = char_to_lower(tmpname[i]);
		}

	if (locptr)
		{
			_location   = locptr;
		}
	if (nameptr)
		{
			_name       = nameptr;
		}
	if (extptr)
		{
			_extension  = extptr;
		}

  free (tmpname);

}

const char* ceFileInfo::GetName() const
{
	return _name.c_str();
}

const char* ceFileInfo::GetExtension() const
{
	return _extension.c_str();
}

const char* ceFileInfo::GetLocation() const
{
	return _location.c_str();
}

